using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;

namespace Elementum
{
    class EndStage : Stage
    {
        public EndStage(Game game)
            : base(game)
        {
        }
        FocusTarget _foucs;
        //List<Image> _cityList;
        List<Image> _lightList;

        public override void InitializeScenes()
        {
            _foucs = new FocusTarget(new Vector2(400, 520));
            camera = new Camera2D(this.Game);
            camera.Position = _foucs.Position;
            camera.Focus = _foucs;
            camera.MoveSpeed = 0.10f;
            Font = ResourceManager.Content.Load<SpriteFont>("SpriteFont1");
           // _cityList = new List<Image>();
            _lightList = new List<Image>();

            for (int i = 0; i < 4; i++) {
                Image img = new Image("images/ed/citynight"+i);
                img.Position = new Vector2(400,240)+new Vector2(1024*i,0);
                actors.Add(img);
            }

            for (int i = 0; i < 5; i++)
            {
                Image img = new Image("images/ed/light" + i);
                img.Position = new Vector2(400-256, 240+360) + new Vector2(512 * i, 0);
                img.Alpha = 0;
                actors.Add(img);
                _lightList.Add(img);
            }

            _song = MusicManager.LoadSong("Music/soul");
            MediaPlayer.Play(_song);

            Transition tra = new DefauldTransition(1, 0, 0, 20);
            tra.Register(this);

        }


        public override void OnDraw(SpriteBatch spriteBatch, int delta)
        {
            base.OnDraw(spriteBatch, delta);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, camera.Transform);
            foreach (VisibleObject b in actors)
                b.OnDraw(spriteBatch, camera.Transform);
            spriteBatch.End();

            //spriteBatch.Begin();
            //spriteBatch.DrawString(Font, "count="+_count, new Vector2(50, 50), Color.LightPink);
           // spriteBatch.DrawString(Font, " camera.Position=" + camera.Position, new Vector2(50, 80), Color.LightPink);
            //spriteBatch.End();
        }

        public override void Update(int delta)
        {
            base.Update(delta);

           _count++;
            

            if (_count == 10)
                _foucs.Position = new Vector2(3000, 520);
            if (_count == 800)
                _foucs.Position = new Vector2(3100, 100);

            if (_count == 5)
            {
                Transition tra;
                tra = new TitleTransition("images/system/gameClear", 0, 1, 120, 170);//gc
                tra.Register(this);
                tra = new TitleTransition("images/system/gameClear", 1, 1, 170, 350);//gc
                tra.Register(this);
                tra = new TitleTransition("images/system/gameClear", 1, 0, 350, 400);//gc
                tra.Register(this);
            }

            if (_count == 50) {
                _lightList[0].Alpha = 1;

            }

            if (_count == 100)
            {
                _lightList[1].Alpha = 1;

            }

            if (_count == 150)
            {
                _lightList[2].Alpha = 1;
               
            }

            if (_count == 350)
            {
                _lightList[3].Alpha = 1;
            }

            if (_count == 600)
            {
                _lightList[4].Alpha = 1;
            }

            if (_count == 1070)
            {
                Transition tra;
                tra = new DefauldTransition(0, 1, 10, 80);
                tra.Register(this);
                tra = new DefauldTransition(1, 1, 80, 400);
                tra.Register(this);
                tra.TransitionDoneAction += this.PressedBackButton;

                tra = new TitleTransition("images/system/stuff", 0, 1, 100, 150);//stuff
                tra.Register(this);
                tra = new TitleTransition("images/system/stuff", 1, 1, 150, 300);//stuff
                tra.Register(this);
                tra = new TitleTransition("images/system/stuff", 1, 0, 300, 350);//stuff
                tra.Register(this);

            }
           

        }

        int _count = 0;

        public override void PressedBackButton()
        {
            GameClass.IsExit = true;
        }

        public override Stage Clone()
        {
            EndStage stage = new EndStage(Game);
            stage.InitializeScenes();
            return stage;
        }


    }
}
